package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.SkuInfo;
import com.atguigu.gmall.model.product.SpuImage;
import com.atguigu.gmall.model.product.SpuInfo;
import com.atguigu.gmall.model.product.SpuSaleAttr;
import com.atguigu.gmall.product.service.BaseManageService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product")
public class SpuManageController {
    //  http://localhost/admin/product/1/10?category3Id=1
    //  /admin/product/{page}/{limit}
    @Autowired
    private BaseManageService baseManageService;

    /**
     *获取spu    分页列表spu
     * @param page
     * @param limit
     * @param spuInfo  里面有参数category3_id
     * @return
     */
    @GetMapping("{page}/{limit}")
    public Result getSpuInfoPage(@PathVariable Long page,
                                 @PathVariable Long limit,
                                 SpuInfo spuInfo){
        // select * from spu_info where category3_id=spuInfo.getCategory3Id() limit 1 ,10
        IPage iPage=new Page(page,limit);
       IPage spuInfoPage=baseManageService.getSpuInfoPage(iPage,spuInfo);
       return Result.ok(spuInfoPage);
    }

    // /admin/product/saveSpuInfo

    /**
     * spu大保存
     * @param spuInfo
     * @return
     */
    @PostMapping("/saveSpuInfo")
    public Result saveSpuInfo(@RequestBody SpuInfo spuInfo){
        baseManageService.saveSpuInfo(spuInfo);
        return Result.ok();
    }
    // /admin/product/spuImageList/{spuId}
    /**
     * spuImage信息显示
     */
    @GetMapping("spuImageList/{spuId}")
    public Result  getSpuImageList(@PathVariable Long spuId){
        List<SpuImage> spuImageList=baseManageService.getSpuImageList(spuId);
        return  Result.ok(spuImageList);
    }

    //  /admin/product/spuSaleAttrList/{spuId}
    /**
     * 根据spuId 查询销售属性
     */
    @GetMapping("/spuSaleAttrList/{spuId}")
    public Result getSpuSaleAttrList(@PathVariable Long spuId){
        List<SpuSaleAttr> spuSaleAttrList = baseManageService.getSpuSaleAttrList(spuId);
        return Result.ok(spuSaleAttrList);
    }
    // /admin/product/saveSkuInfo



}
